package com.cn.common.model;

import lombok.Data;

import java.io.Serializable;

public class Result<T> implements Serializable {
    private static final long serialVersionUID = -6493079816439551759L;
    private int code;
    private String msg = "";
    private T data = null;
    private boolean success = true;

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(boolean _success, int code, String msg, T data) {
        this.success = _success;
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result(boolean _success, int code, String msg, T data, String traceId) {
        this.success = _success;
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static Result build(boolean _result) {
        return _result ? success("操作成功") : error("操作成功");
    }

    public static Result success() {
        return success("操作成功");
    }

    public static <T> Result success(T data) {
        return success("操作成功", data);
    }

    public static Result success(String msg) {
        return success(msg, (Object)null);
    }

    public static <T> Result success(int code, String msg, T data) {
        return new Result(true, code, msg, data);
    }

    public static <T> Result success(int code, String msg) {
        return new Result(true, code, msg, (Object)null);
    }

    public static <T> Result success(String msg, T data) {
        return new Result(true, 1, msg, data);
    }

    public static Result error() {
        return error("操作失败");
    }

    public static Result error(String msg) {
        return error(0, msg);
    }

    public static <T> Result error(String msg, T data) {
        return new Result(false, 500, msg, data);
    }

    public static <T> Result error(int code, String msg, T data) {
        return new Result(false, code, msg, data);
    }

    public static Result error(int code, String msg) {
        return new Result(false, code, msg, (Object)null);
    }

    public boolean isSuccess() {
        return this.success;
    }

    public boolean getSuccess() {
        return this.success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public int getCode() {
        return this.code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return this.msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}